
#include "Publisher.h"
#include <algorithm>

void Publisher::AddObserver(Observer* o)
{
  observers_->push_back(o);
}

void Publisher::DelObserver(Observer* o)
{
  observers_->remove(o);
}

void Publisher::Publish(Event* e)
{
  std::for_each(observers_->begin(),
                observers_->end(),
                [=](Observer* o) {
                  o->DoSomething(e);
                });
}

Publisher::~Publisher()
{
  delete observers_;
  observers_ = nullptr;
}

Publisher::Publisher()
{
  observers_ = new std::list<Observer*>();
}
